package Utils;

import java.util.HashMap;
import java.util.Map;

import ranks.Admin;
import ranks.Moderator;
import ranks.Normal;
import ranks.Rank;
import main.User;

public class Utils {
   
   public static Map<String, Rank> rankMap;
   
   public static Rank getIPRank(User user) {
      rankMap = new HashMap<String, Rank>();
      rankMap.put("_robfox", new Admin(user));
      rankMap.put("raid0", new Moderator(user));
      
      Rank rank = rankMap.get(user.name);
      if (rank != null) return rank;
      return new Normal(user);
   }
   
   /**
    * Removes the indexed word from the string.<br>
    * PS! If the index is out of bounds the method will return a null object.
    */
   public static String cutWordFromString(String word, int index) {
      String[] words = word.split(" ");
      String newLine = "";
      if (words.length < index - 1) {
         return null;
      }
      for (int i = 0; i < words.length; i++) {
         if (i == index) continue;
         newLine += words[i];
         if (i+1 < words.length) {
            newLine += " ";
         }
      }
      return newLine;
   }
}
